package com.mdp.im.core.publish.action.impl;

import com.alibaba.fastjson.JSONObject;
import com.mdp.im.core.entity.ImGroup;
import com.mdp.im.core.publish.action.AbstractPublishAction;
import com.mdp.im.core.publish.api.action.PublishAction;
import com.mdp.im.core.publish.api.Publisher;
import com.mdp.im.core.publish.api.StorePublisher;
import com.mdp.im.core.service.ImGroupMessageService;
import com.mdp.im.core.service.ImGroupService;
import com.mdp.im.core.service.ImGroupUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 群组名称改变处理器
 * 
 * @author chenyc
 * @date 2018/6/8
 */
@Service("pushChannelGroupNameChangedAction")
public class ChannelGroupNameChangedAction extends AbstractPublishAction implements PublishAction {

	@Autowired
	ImGroupService groupService;
	
	@Autowired
	ImGroupUserService groupUserService;
	
	@Autowired
	ImGroupMessageService groupMessageService;
	
	@Autowired
	Publisher publisher;


	@Autowired
	StorePublisher storePublisher;
	
    /**
     * 处理消息
     * 
     * @param message
     */
    @Override
    public void doAction(JSONObject message) {
    	String groupId=message.getString("groupId");
    	 ImGroup group=new ImGroup();
    	 group.setId(groupId);
    	 group.setGroupName(message.getString("groupName")); 
    	 group.setLastUpdateTime(new Date());
    	 groupService.updateSomeFieldByPk(group);
    	 String msg= message.toJSONString();
    	 publisher.publishGroupMessage(groupId,msg);
		storePublisher.publishGroupMessageToDbQueue(msg);
         
    }

}
